package text1;

import java.util.Scanner;

public class DvdSystem {
    String [] names=new String[6];//存放电影名
    double [] rental=new double[6];//存放DVD的价格；
    boolean [] isborrow=new boolean[6];//存放是否借出；
    String [] releaseTime=new String[6];

    public void firstValue(){
        names[0]="战狼2";
        rental[0]=20.8;
        isborrow[0]=false;
        releaseTime[0]="2020-6-5";

        names[1]="杀破狼2";
        rental[1]=10.9;
        isborrow[1]=false;
        releaseTime[1]="2020-6-5";

        names[2]="复仇者联盟";
        rental[2]=38.9;
        isborrow[2]=false;
        releaseTime[2]="2020-12-5";

        names[3]="钢铁侠";
        rental[3]=29.3;
        isborrow[3]=false;
        releaseTime[3]="2020-5-5";

        names[4]="寒战";
        rental[4]=28;
        isborrow[4]=false;
        releaseTime[4]="2020-6-5";
    }
    public void showMainMenu(){
        System.out.println("欢迎使用DVD租用系统~");
        System.out.println("请选择操作");
        System.out.println("1：查看所有电影");
        System.out.println("2：新增电影");
        System.out.println("3：借出电影");
        System.out.println("4：归还电影");
        System.out.println("5：删除电影");
        System.out.println("6：删除所有电影");
    }

    public void showOneMenu(){
        System.out.println("==查看所有电影==");
        System.out.println("电影名\t电影租金\t上映时间\t\t租借状态");
        for(int i=0;i<names.length;i++){
            if(names[i]!=null&&!"".equals(names[i].trim())){
                System.out.println(names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t"+(isborrow[i]==true?"借出":"未借出"));
            }
        }
    }

    public void showTwoMenu(){
        Scanner input=new Scanner(System.in);
        System.out.println("==新增电影==");
//赋值部分
        int index =-1;
        for(int i=0;i<names.length;i++){
            if(names[i]==null){
                index=i;
                break;
            }
        }
        if(index!=-1){
            System.out.println("请输入新增电影名");
            String newName=input.next();
            System.out.println("请输入租金");
            double newRental=input.nextDouble();
            System.out.println("请输入上映时间");
            String newReleaseTime=input.next();
            names[index]=newName;
            rental[index]=newRental;
            releaseTime[index]=newReleaseTime;
            isborrow[index]=false;
            System.out.println("录入成功");
        }else{
            System.out.println("磁盘已满，无法录入~");
        }
    }
    public void showThrMenu(){
        Scanner input=new Scanner(System.in);
        System.out.println("==借出电影==");
        System.out.println("您可以租借如下电影：");
        System.out.println("电影名\t电影租金\t上映时间\t租借状态");
        for(int i=0;i<names.length;i++){
            if(isborrow[i]!=true&&names[i]!=null&&!"".equals(names[i].trim())){
                System.out.println((i+1)+"\t"+names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t\t"+(isborrow[i]==true?"借出":"未借出"));
            }
        }
        System.out.println("请选择你要租借的电影");
        int choose=input.nextInt();
        isborrow[choose-1]=true;
        System.out.println("请输入租借的天数");
        int day=input.nextInt();
        switch (choose) {
            case 1:
                System.out.println("电影信息："+names[0]+"\t租金合计："+day*rental[0]);
                break;
            case 2:
                System.out.println("电影"+names[1]+"\t租金合计："+day*rental[1]);
                break;
            case 3:
                System.out.println("电影"+names[2]+"\t租金合计："+day*rental[2]);
                break;
            case 4:
                System.out.println("电影"+names[3]+"\t租金合计："+day*rental[3]);
                break;
            case 5:
                System.out.println("电影"+names[4]+"\t租金合计："+day*rental[4]);
                break;
            case 6:
                System.out.println("电影"+names[5]+"\t租金合计："+day*rental[5]);
                break;
            default:
                break;
        }
    }
    public void showFourMenu(){
        Scanner input=new Scanner(System.in);
        System.out.println("==归还电影==");
        System.out.println("请输入归还的电名：");
        String rebackname=input.next();
        for(int i=0;i<names.length;i++){
            if(rebackname.equals(names[i])){
                isborrow[i]=false;
            }
        }
        System.out.println("归还成功");
    }
    public void showFiveMenu(){
        Scanner input=new Scanner(System.in);
        System.out.println("==删除电影==");
        System.out.println("请选择删除的电影");
        for(int i=0;i<names.length;i++){
            if(names[i]!=null&&!"".equals(names[i].trim())){
                System.out.println((i+1)+"\t"+names[i]+"\t"+rental[i]+"\t"+releaseTime[i]+"\t"+(isborrow[i]==true?"借出":"未借出"));
            }
        }
        int choose=input.nextInt();
        for(int i=0;i<names.length-1;i++){
            if(i<choose-1){
                names[i]=names[i];
                rental[i]=rental[i];
                releaseTime[i]=releaseTime[i];
                isborrow[i]=isborrow[i];
            }else {
                names[i]=names[i+1];
                rental[i]=rental[i+1];
                releaseTime[i]=releaseTime[i+1];
                isborrow[i]=isborrow[i+1];
            }
        }
        names[names.length-1]=null;
        rental[names.length-1]=0.0;
        releaseTime[names.length-1]=null;
        isborrow[names.length-1]=false;
        System.out.println("删除成功！");
    }
    public void showSixMenu(){
        System.out.println("==删除所有电影==");
        for(int i=0;i<names.length;i++){
            names[i]=null;
            rental[i]=0.0;
            releaseTime[i]=null;
            isborrow[i]=false;
        }
        System.out.println("删除成功");
    }
}